﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BasePlatformCom
{
	public class SubControlInfo
	{
		public int index = -1;					// 索引
		public string version = "";				// 版本号

		public int[] p_total = new int[9];		// 总点数
		public int[] p_err = new int[9];		// 错误点数
		
		public string[] lightDetail = new string[9];		// 灯条错灯检测信息
		public byte[][] lightDetailBytes = new byte[9][];	// 灯条错灯检测信息字节

		public bool hasWatchCard = false;					// 是否连接了箱体监控卡
		public byte[] watchCardInfoBytes = new byte[0x1F];	// 箱体监控卡信息字节

		public uint crc_err_count = 0;			// 总包数
		public uint package_count = 0;			// 错误包数

		public byte[] replyData = new byte[256];
		
		// 构造函数
		public SubControlInfo()
		{
			for (int k = 0; k < 9; k++)
			{
				lightDetailBytes[k] = new byte[256];
			}
		}

		// 构造函数
		public void setPortInfo(int[] p_t, int[] p_e)
		{
			for (int k = 0; k < 9; k++)
			{
				p_total[k] = p_t[k];
				p_err[k] = p_e[k];
			}
		}

		// 设置灯条错灯检测信息
		public void setLightDetail(int portIndex, string data)
		{
			if (data != null)
			{
				lightDetail[portIndex] = data;
			}
		}

		// 设置灯条错灯检测信息字节
		public void setLightDetailBytes(int portIndex, byte[] data)
		{
			if (data != null)
			{
				Array.Copy(data, lightDetailBytes[portIndex], 256);
			}
		}

		// 设置箱体监控卡信息字节
		public void setWatchCardInfoBytes(byte[] value)
		{
			Array.Copy(value, watchCardInfoBytes, 0x6F - 0x50);
		}

		// 复制数据结构
		public SubControlInfo clone()
		{
			SubControlInfo copy = new SubControlInfo();

			copy.index = index;
			copy.version = version;

			for (int k = 0; k < 9; k++)
			{
				copy.p_total[k] = p_total[k];
				copy.p_err[k] = p_err[k];
				copy.lightDetail[k] = lightDetail[k];
				Array.Copy(lightDetailBytes[k], copy.lightDetailBytes[k], 256);
			}

			copy.hasWatchCard = hasWatchCard;

			for (int k = 0; k < 0x1F; k++)
			{
				copy.watchCardInfoBytes[k] = watchCardInfoBytes[k];
			}

			copy.crc_err_count = crc_err_count;
			copy.package_count = package_count;

			Array.Copy(replyData, copy.replyData, 256);

			return copy;
		}
	}
}
